import type { FieldRule } from '@arco-design/web-vue'

export const randomCname = () => {
  const char = 'abcdefghijklmnopqrstuvwxyz0123456789'
  let len = 6
  let result = ''
  while (len > 0) {
    const index = Math.floor(Math.random() * char.length)
    result += char[index]
    len--
  }
  return result
}
export const cnameRules: FieldRule = {
  required: true,
  validator(value, callback) {
    const reg = /^[0-9a-z]{6,20}$/

    if (!value) {
      callback('CNAME 不能为空')
    } else if (!reg.test(value)) {
      callback('请输入6 ~ 20 位小写字母和数字')
    } else {
      callback()
    }
  }
}
